<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="../../resources/templates/login.xhtml"
                xmlns:p="http://primefaces.org/ui"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:sec="http://www.springframework.org/security/facelets/tags" >

    <ui:define name="menu_horizontal">
        <sec:ifAnyGranted roles="ROLE_SERVIDOR,ROLE_ADMINISTRADOR">
            <ui:include src="/site/acessoServidor/menu.xhtml" />
        </sec:ifAnyGranted>
    </ui:define>

    <ui:define name="corpo">
        <sec:ifAnyGranted roles="ROLE_SERVIDOR,ROLE_ADMINISTRADOR">

            <h:form id="formSalvar">
                <p:panel  header="Manter Classe"> 
                    <p:messages id="msgs"/> 
                    <h:panelGrid columns="2" >

                        Turma:<p:selectOneMenu value="#{controllerClasse.classe.turma}" converter="#{TurmaConverter}" style="width: 350px">
                            <f:selectItem itemLabel="-- Selecione --" noSelectionOption="true"/>
                            <f:selectItems value="#{controllerTurma.lista}" var="tipo" itemValue="#{tipo}" 
                                           itemLabel="#{tipo.periodoletivo.ano}/#{tipo.periodoletivo.semestre} - #{tipo.matrizcurricular.curso.nome} T#{tipo.numero_turma} - #{tipo.turno}"/>
                        </p:selectOneMenu>
                        
                        Dia da Semana:<p:selectOneMenu value="#{controllerClasse.horario.dia_semana}" style="width: 200px">
                            <f:selectItem itemLabel="-- Selecione --" noSelectionOption="true"/>
                            <f:selectItem itemLabel="Segunda-feira" itemValue="Segunda" />
                            <f:selectItem itemLabel="Terça-feira" itemValue="Terça" />
                            <f:selectItem itemLabel="Quarta-feira" itemValue="Quarta" />
                            <f:selectItem itemLabel="Quinta-feira" itemValue="Quinta" />
                            <f:selectItem itemLabel="Sexta-feira" itemValue="Sexta" />
                            <f:selectItem itemLabel="Sábado" itemValue="Sábado" />
                        </p:selectOneMenu>

                        Horário Início: <p:calendar value="#{controllerClasse.horario.horario_inicio}" pattern="HH:mm" timeOnly="true" locale="pt_BR"  style="width: 200px"/>
                        Horário Fim: <p:calendar value="#{controllerClasse.horario.horario_fim}" pattern="HH:mm" timeOnly="true"/>

                        Disciplina: <p:selectOneMenu value="#{controllerClasse.classe.disciplina}" converter="#{DisciplinaConverter}" style="width: 200px">
                            <f:selectItem itemLabel="-- Selecione --" noSelectionOption="true"/>
                            <f:selectItems value="#{controllerDisciplina.listaDisc}" var="tipo" itemValue="#{tipo}" itemLabel="#{tipo.codigo}"/>
                        </p:selectOneMenu>

                        Professor:  <p:selectOneMenu value="#{controllerClasse.classe.servidor}" converter="#{ServidorConverter}" style="width: 200px">
                            <f:selectItem itemLabel="-- Selecione --" noSelectionOption="true"/>
                            <f:selectItems value="#{controllerServidor.lista}" var="tipo" itemValue="#{tipo}" itemLabel="#{tipo.nome}"/>
                        </p:selectOneMenu>                    


                        <p:commandButton value="Salvar"   update="@form" actionListener="#{controllerClasse.salvarClasseH()}"/>





                    </h:panelGrid>
                </p:panel>

                <p:dataTable id="tabela" var="p" value="#{controllerClasse.listaDMClasse}" emptyMessage="Nada encontrado..."
                             paginator="true" rows="5" paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" 
                             rowsPerPageTemplate="5,10,15"   >
                    <p:column headerText="Disciplina" filterBy="#{p.disciplina.unidade_curricular}">
                        <h:outputText value="#{p.disciplina.unidade_curricular} (#{p.disciplina.codigo})"/>
                    </p:column>
                    <p:column headerText="Dia da semana" filterBy="#{p.horario.dia_semana}">
                        <h:outputText value="#{p.horario.dia_semana}"/>
                    </p:column>
                    <p:column headerText="Horario de Inicio">
                        <h:outputText value="#{p.horario.horario_inicio}">
                            <f:convertDateTime pattern="HH:mm:ss" timeZone="GMT-03:00"/>
                        </h:outputText>
                    </p:column>
                    <p:column headerText="Horario de Fim">
                        <h:outputText value="#{p.horario.horario_fim}">
                            <f:convertDateTime pattern="HH:mm:ss" timeZone="GMT-03:00"/>
                        </h:outputText>
                    </p:column>


                    <p:column headerText="Professor" filterBy="#{p.servidor.nome}">
                        <h:outputText value="#{p.servidor.nome}"/>

                    </p:column>

                    <p:column width="75">
                        <p:commandLink  actionListener="#{controllerClasse.prepararAlterarClasse()}" ajax="true" process="@this" oncomplete="dialogAlterarClasse.show();" update=":formAlterarClasse">
                            <p:graphicImage  value="/resources/images/editC.png" />
                        </p:commandLink>

                        <p:commandLink  actionListener="#{controllerClasse.prepararAlterarHorario()}" ajax="true" process="@this" oncomplete="dialogAlterarHorario.show();" update=":formAlterarHorario">
                            <p:graphicImage  value="/resources/images/editH.png" />
                        </p:commandLink>


                        <p:commandLink  actionListener="#{controllerClasse.removerClasse()}" ajax="true" process="@this" update="@form">
                            <p:graphicImage  value="/resources/images/delete.png" />                      
                        </p:commandLink>
                    </p:column>     

                </p:dataTable>




            </h:form>

            <p:dialog widgetVar="dialogAlterarClasse" resizable="false" closable="false" modal="true" showEffect="slide" hideEffect="slide">
                <h:form id="formAlterarClasse">
                    <p:panel style="width: 500px;">
                        <p:messages id="msgs"/> 
                        <h:panelGrid columns="2">

                            Turma:<p:selectOneMenu value="#{controllerClasse.classe.turma}" converter="#{TurmaConverter}" style="width: 350px">
                            <f:selectItem itemLabel="-- Selecione --" noSelectionOption="true"/>
                            <f:selectItems value="#{controllerTurma.lista}" var="tipo" itemValue="#{tipo}" 
                                           itemLabel="#{tipo.periodoletivo.ano}/#{tipo.periodoletivo.semestre} - #{tipo.matrizcurricular.curso.nome} T#{tipo.numero_turma} - #{tipo.turno}"/>
                        </p:selectOneMenu>


                            Disciplina: <p:selectOneMenu value="#{controllerClasse.classe.disciplina}" converter="#{DisciplinaConverter}" style="width: 200px">

                                <f:selectItems value="#{controllerDisciplina.listaDisc}" var="tipo" itemValue="#{tipo}" itemLabel="#{tipo.unidade_curricular}"/>
                            </p:selectOneMenu>



                            Professor:  <p:selectOneMenu value="#{controllerClasse.classe.servidor}" converter="#{ServidorConverter}" style="width: 200px">

                                <f:selectItems value="#{controllerServidor.lista}" var="tipo" itemValue="#{tipo}" itemLabel="#{tipo.nome}"/>
                            </p:selectOneMenu>                    


                            <p:commandButton value="Alterar" actionListener="#{controllerClasse.alterarClasse()}" oncomplete="dialogAlterarClasse.hide()" update=":formSalvar" 
                                             style="margin-top: 30px"/>
                            <p:commandButton value="cancelar" actionListener="#{controllerClasse.limparClasse()}" oncomplete="dialogAlterarClasse.hide()" update=":formSalvar" 
                                             style="margin-top: 30px;margin-left: 0px;"/>
                        </h:panelGrid>
                    </p:panel>
                </h:form>
            </p:dialog>


            <p:dialog widgetVar="dialogAlterarHorario" resizable="false" closable="false" modal="true" showEffect="slide" hideEffect="slide">
                <h:form id="formAlterarHorario">
                    <p:panel style="width: 320px;">
                        <p:messages id="msgs"/> 
                        <h:panelGrid columns="2">
                            
                            Dia da Semana:<p:selectOneMenu value="#{controllerClasse.horario.dia_semana}" style="width: 200px">
                            <f:selectItem itemLabel="Segunda-feira" itemValue="Segunda" />
                            <f:selectItem itemLabel="Terça-feira" itemValue="Terça" />
                            <f:selectItem itemLabel="Quarta-feira" itemValue="Quarta" />
                            <f:selectItem itemLabel="Quinta-feira" itemValue="Quinta" />
                            <f:selectItem itemLabel="Sexta-feira" itemValue="Sexta" />
                            <f:selectItem itemLabel="Sábado" itemValue="Sábado" />
                        </p:selectOneMenu>


                            Horário Início: <p:calendar value="#{controllerClasse.horario.horario_inicio}" pattern="HH:mm" timeOnly="true" style="width: 200px"/>
                            Horário Fim: <p:calendar value="#{controllerClasse.horario.horario_fim}" pattern="HH:mm" timeOnly="true" style="width: 200px"/>
                            



                            <p:commandButton value="Alterar" actionListener="#{controllerClasse.alterarHorario()}" oncomplete="dialogAlterarHorario.hide()" update=":formSalvar" 
                                             style="margin-top: 30px"/>
                            <p:commandButton value="cancelar" actionListener="#{controllerClasse.limparHorario()}" oncomplete="dialogAlterarHorario.hide()" update=":formSalvar" 
                                             style="margin-top: 30px;margin-left: 0px;"/>
                        </h:panelGrid>
                    </p:panel>
                </h:form>
            </p:dialog>


        </sec:ifAnyGranted>
    </ui:define>

</ui:composition>
